package com.mercator.client.graph;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;

public class GenClique implements Comparable<GenClique>  {

	LinkedList<String> ontologies;public Set<GeneSet> genesets; LinkedList<Gene> genes;
	public GenClique(LinkedList<String>  ontologies,Set<GeneSet> genesets, LinkedList<Gene> genes){
		this.ontologies = ontologies;
		this.genesets = genesets;
		this.genes = genes;
	}
	
	public GenClique(Set<GeneSet> genesets){
		this.ontologies = new LinkedList<String>();
		this.genesets = new HashSet<GeneSet>();
		if(!genesets.isEmpty())
			this.genesets.addAll(genesets);
		//this.genesets.addAll(genesets);
		this.genes = new LinkedList<Gene>();
	}
	
	public void addGene(Gene g){
		genes.add(g);
	}
	
	public void addOntology(String s){
		ontologies.add(s);
	}
	
	
	public boolean containsAll(GenClique gc){
		return genesets.containsAll(gc.genesets);
		
	}
	
	
	
	
	public int compareTo(GenClique o) {
		if(this.genesets.size() > o.genesets.size())
			return -1;
		else if (this.genesets.size() < o.genesets.size())
			return 1;
		return this.hashCode() - o.hashCode();
	}
	
	public String toString(){
		return genesets.toString();
	}
	
	@Override
	public boolean equals(Object m){
		GenClique other = ((GenClique)m);
		boolean equal = true;
		if (other.genesets.size() != this.genesets.size())
			equal = false;
		else
			equal = this.genesets.containsAll(other.genesets);
		return equal;
	}
	@Override
	public int hashCode(){
		int hash=0;
		int i = 1;
		for(GeneSet gs : genesets){
			hash += gs.hashCode() *i;
		i*=10;}
		return hash;
	}

}
